package com.yuhong.springbootinit.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuhong.springbootinit.model.entity.UserProfile;
import com.yuhong.springbootinit.model.entity.Candidate;
import com.yuhong.springbootinit.model.entity.Invitation;
import com.yuhong.springbootinit.service.CandidateService;
import com.yuhong.springbootinit.mapper.CandidateMapper;
import com.yuhong.springbootinit.service.UserProfileService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author 10467
* @description 针对表【candidate】的数据库操作Service实现
* @createDate 2025-02-22 13:52:10
*/
@Service
public class CandidateServiceImpl extends ServiceImpl<CandidateMapper, Candidate>
    implements CandidateService{

    @Resource
    private UserProfileService userProfileService;

    @Override
    public boolean addCandidate(Invitation invitation) {

        String userId = invitation.getUserId();

        Candidate candidate = new Candidate();

        QueryWrapper<UserProfile> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(UserProfile::getUserId, userId);
        UserProfile userProfile = userProfileService.getOne(queryWrapper);

        BeanUtil.copyProperties(invitation,candidate);
        candidate.setProfileId(userProfile.getProfileId());
        candidate.setUserName(userProfile.getUserId());

        return save(candidate);
    }
}




